#ifndef ELALERT_H
#define ELALERT_H

#include "../basic/elcomponent.h"
#include "../basic/eltheme.h"

class ElIcon;
class ElTextButton;
class QPropertyAnimation;

class ElAlert : public ElComponent
{
    Q_OBJECT
public:
    enum Effect { Dark, Light };
    enum Type { Success, Warning, Info, Error };
    enum CloseBehavior { Delete, KeepOn };

    ElAlert(QWidget *parent);
    ElAlert(QWidget *parent, const QString &title, const QString &description = QString());

    void setWidth(int w);

    QString title() const;
    void setTitle(const QString &title);

    QString description() const;
    void setDescription(const QString &description);

    Type type() const;
    void setType(Type type);

    Effect effect() const;
    void setEffect(Effect effect);

    bool isClosable() const;
    void setClosable(bool closable);

    bool isCenter() const;
    void setCenter(bool center);

    bool isShowIcon() const;
    void setShowIcon(bool showIcon);

    QString closeText() const;
    void setCloseText(const QString &closeText);

    CloseBehavior closeBehavior() const;
    void setCloseBehavior(CloseBehavior behavior);

    static const int Icon_Size;
    static const int Padding_Lr;
    static const int Padding_Tb;
    static const int Init_Width;
    static const int Icon_Text_Spacing;
    static const int Title_Desc_Spacing;

signals:
    void shutAfter();

public slots:
    void shut();

protected:
    void paintEvent(QPaintEvent *e) override;
    void initPalette() override;

private:
    Q_PROPERTY(QString title READ title WRITE setTitle)
    Q_PROPERTY(QString description READ description WRITE setDescription)
    Q_PROPERTY(Type type READ type WRITE setType)
    Q_PROPERTY(Effect effect READ effect WRITE setEffect)
    Q_PROPERTY(bool closable READ isClosable WRITE setClosable)
    Q_PROPERTY(QString closeText READ closeText WRITE setCloseText)
    Q_PROPERTY(bool center READ isCenter WRITE setCenter)
    Q_PROPERTY(bool showIcon READ isShowIcon WRITE setShowIcon)

    QString _title;
    QString _description;
    ElTheme _theme = ElTheme::Information;
    bool _closable = true;
    QString _close_text = "×";
    bool _center = false;
    bool _show_icon = false;
    Effect _effect = Light;
    CloseBehavior _close_behavior = Delete;

    ElIcon *_icon = nullptr;
    ElTextButton *_closeBtn = nullptr;
    QPropertyAnimation *_animOpa = nullptr;
    bool _is_repeat_click = false;

    void initAnimation();
    void createCloseBtn();
    void updateCloseBtn();
};

#endif // ELALERT_H
